console.log('--------------------------------------事件总线--------------------------')


function Event() {
    this.subs = {}
}

Event.prototype.$on = function (name, callback) {
    this.subs[name] = this.subs[name] || []
    this.subs[name].push(callback)
}

Event.prototype.$emit = function (name, ...args) {
    this.subs[name] && this.subs[name].forEach(item => {
        item.call(this, ...args)
    })
}

const eventBus = new Event()

eventBus.$on('test1', function (a) {
    console.log(a)
})
eventBus.$emit('test1', 123)